import time

_in = input()

def f(n):
    if len(n) == 1:
        print(n)
    else:
        m = 0
        for i in n:
            m += int(i)
            # time.sleep(1)
        print(m)
        return f(str(m))


f(_in)